function [result] = note_args(str, n)
% note_args : parse an acquisition string from the note reader
% returns the nth argument in result as a string
% Operation: first, deblank the data completely, leaving only single spaces
% get token list
% return contents of s(j+1:k) where j= this token and k = next token
% Modified 11/23/00: n can be a vector, in which case all the elements of the vector are returned
result = '';
dstr = '';
str=deblank(str);
j=1;
nspc=0;
% this is the deblanking routine (makes ONE blank for each group thereof)
for i=1:length(str)
   if(strcmp(str(i), ' '))
      nspc = nspc+1;
   else
      if(nspc > 0)
         dstr(j)=' '; % put in one space
         j=j+1;
         dstr(j)=str(i); % copy over the character
         j=j+1;
         nspc=0;	% reset space counter
      else
         dstr(j)=str(i); % no spaces - just copy over
         j=j+1;
      end
   end
end
% now parse out the token list
% if n is positive, we want the n'th token
% if n is an array, we want the [n1 n2 n3] tokens
% if n is negative (single number), we want nth through end tokens.
%
a=findstr(dstr, ' ');
ntok=length(a);
result = [];
if(length(n) > 1) % array - directs outputs
   for i = n
      if(i == (length(a)+1))
         result = [result ' ' dstr(a(i)+1:end)];
      elseif i == 1
         result = [result ' ' dstr(1:a(1)-1)];
      elseif i <= length(a)
         result=[result ' ' dstr(a(i-1)+1:a(i)-1)];
      end;
   end;
elseif n > 0 % single number, positive
   if(n == (length(a)+1))
      result = [result dstr(a(n)+1:end)];
   elseif n == 1
      result = dstr(1:a(1)-1);
   elseif n <= length(a)
      result=[result dstr(a(n-1)+1:a(n)-1)];
   end;
else % single number, negative
   n = abs(n);
   if(n > 1 & n <= length(a)+1)
      result = dstr(a(n-1)+1:end);
   elseif n == 1
      result = dstr; % must be whole stringe
   end;
   
end;
return


